package vn.personal.anhht.bloback12.database;

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class CallBlockDatabaseHelper extends SQLiteOpenHelper{


	private static final String DATABASE_CREATE = "CREATE TABLE blacklists ("
			+ "id integer primary key autoincrement, "
			+ "fullname text not null, "
			+ "phone text not null,"
			+ "isBlockCall integer,"
			+ "isBlockSms integer," 
			+ "isWhiteList integer);";
	private static final String CREATE_TABLE_SMS = "CREATE TABLE smss ("
			+ "id integer primary key autoincrement, " 
			+ "phone_from text not null, "
			+ "receive_time text not null, " 
			+ "content text, " 
			+ "type text); ";
	private static final String CREATE_TABLE_FILTER = "CREATE TABLE filters ("
			+ "id integer primary key autoincrement, "  
			+ "word text); ";
	private static final String CREATE_TABLE_CALLS_BLOCK = "CREATE TABLE callsblock ("
            + "id integer primary key autoincrement, "
            + "fullname text, "
            + "phone text, "
            + "time text, "
            + "type integer);";
	
	private static final String DATABASE_DROPTABLE = "DROP TABLE IF EXIST blacklists";
	private static final String DATABASE_DROPTABLE_SMS = "DROP TABLE IF EXIST smss";
	private static final String DATABASE_DROPTABLE_FILTERS = "DROP TABLE IF EXIST filters";
	private static final String DATABASE_DROPTABLE_CALLSBLOCK = "DROP TABLE IF EXIST callsblock";
	private static final String DATABASE_NAME = "callblock";
	private static final int DATABASE_VERSION = 2;
	/**
	 * 		
	 * @param _context
	 */
	public CallBlockDatabaseHelper(android.content.Context _context){
		super(_context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	/**
	 * 	create in the first time
	 */
	public void onCreate(SQLiteDatabase _database){
	    Log.e("DATABASE", "ONCREATE THE FIRST");
		_database.execSQL(DATABASE_CREATE);
		_database.execSQL(CREATE_TABLE_SMS);
		_database.execSQL(CREATE_TABLE_FILTER);
		_database.execSQL(CREATE_TABLE_CALLS_BLOCK);
	}
	/**
	 * 
	 */
	public void onUpgrade(SQLiteDatabase _database, int oldVersion, int newVersion){
		_database.execSQL(DATABASE_DROPTABLE);
		_database.execSQL(DATABASE_DROPTABLE_SMS);
	    _database.execSQL(DATABASE_DROPTABLE_FILTERS);
	    _database.execSQL(DATABASE_DROPTABLE_CALLSBLOCK);
		onCreate(_database);
	}
}
